<template>
	<view class="store-home">
		<scroll-view class="main" scroll-y="true" @scroll="scrollHome" @scrolltolower="getAllGoods()">
			<u-swiper :list="slideshowlist" height="600"></u-swiper>

			<!-- 品牌保证 -->
			<view id="guarantee" class="guarantee">
				<view class="item">
					<image src="https://gbay1.dcyu.com/uploads/images/shop_icon1.png" mode=""></image>
					<view class="text">正品溯源</view>
				</view>
				<view class="item">
					<image src="https://gbay1.dcyu.com/uploads/images/shop_icon2.png" mode=""></image>
					<view class="text">假一赔十</view>
				</view>
				<view class="item">
					<image src="https://gbay1.dcyu.com/uploads/images/shop_icon3.png" mode=""></image>
					<view class="text">产地直邮</view>
				</view>
			</view>
			<!-- 热卖推荐 -->
			<view class="recommend">
				<view class="top">
					<view class="title">热卖推荐</view>
					<view class="subtitle">
						<span></span>
						<text>HOT SALES</text>
						<span></span>
					</view>
				</view>
				<view class="recommend-goods">
					<view class="item" v-for="(item, index) in storeinfo.recommend" :key="index"
						@click="goGoodsDetail(item)">
						<image :src="item.image" mode=""></image>
						<view class="name">{{ item.store_name }}</view>
						<view class="price">{{ item.price }}</view>
					</view>
				</view>
			</view>

			<!-- 优选好货 -->
			<view class="recommend">
				<view class="top">
					<view class="title">优选好货</view>
					<view class="subtitle">
						<span></span>
						<text>RECOMMENDED GOODS</text>
						<span></span>
					</view>
				</view>
				<view class="recommend-goods">
					<view class="item" v-for="(item, index) in storeinfo.optimal" :key="index"
						@click="goGoodsDetail(item)">
						<image :src="item.image" mode=""></image>
						<view class="name">{{ item.store_name }}</view>
						<view class="price">{{ item.price }}</view>
					</view>
				</view>
			</view>

			<!-- 店铺栏 -->
			<view class="store">
				<image style="background-color: #FFFFFF;" :src="storeinfo.mer_avatar"></image>
				<view class="text">
					<text class="name">{{ storeinfo.mer_name }}</text>
					<view class="score">
						<u-rate :disabled="true" size="24" :count="count" v-model="storeinfo.product_score"></u-rate>
						<span
							style="padding-left: 10rpx; font-size: 26rpx;color: #000000;">{{ storeinfo.product_score }}</span>
					</view>
				</view>
				<view class="goodssum">
					<view class="sum">{{ storeinfo.totalProduct }}</view>
					<view class="ww">全部商品</view>
				</view>
			</view>

			<!-- 商品 -->
			<view class="goods-wrap">
				<view class="top">
					<view class="title">全部商品</view>
					<view class="subtitle">
						<span></span>
						<text>HOT SALES</text>
						<span></span>
					</view>
				</view>
				<view v-if="allgoods.length" :class="{ column: isColumn }" class="goods">
					<view v-for="item in allgoods" :key="item.product_id" class="item"
						@click="goGoodsDetail(item)">
						<view class="image">
							<image :src="item.image"></image>
						</view>
						<view class="text">
							<view class="name">{{ item.store_name }}</view>
							<view class="money-wrap">
								<view class="money">
									¥
									<text>{{ item.price }}</text>
								</view>
								<view class="label">
									<view class="ticket" v-if="item.issetCoupon">{{ i18n.Get }}</view>
									<view class="ticket">{{ i18n.Importedgoods }}</view>
									<view class="ticket">{{ i18n.Crossborderdirect }}</view>
									<view class="pinkage">{{ i18n.Pinkage }}</view>
								</view>
							</view>
							<view class="score">{{ item.rate }}{{ i18n.Score }}
								{{ item.reply_count }}{{ i18n.Comments }}</view>
						</view>
						<view v-if="item.max_extension" class="foot">
							<text v-show="!isColumn" class="iconfont"></text>
							{{ i18n.Earn }} ¥{{ item.max_extension }}
						</view>
					</view>
				</view>
			</view>
			<view style="text-align: center; margin-bottom: 10rpx; font-size: 24rpx;">{{ loadTitle }}</view>
		</scroll-view>
	</view>
</template>
<script>
	import {
		mapGetters
	} from 'vuex';
	const globalData = getApp().globalData;
	export default {
		props: {
			slideshowlist: '', //轮播列表
			storeinfo: '',
			allgoods: '',
			loadTitle: '',
			isColumn:true,
		},
		data() {
			return {
				storeHeight:'',
				mer_id:globalData.mer_id,
				count:5.0,
			};
		},
		computed: {
			i18n() {
				return globalData.$t('home');
			},
			...mapGetters(['isLogin'])
		},
		created: function() {},
		methods: {
			//获得全部商品
			getAllGoods: function() {
				this.$emit("getAllGoods", this.getAllGoods);
			},
			//去详情页
			goGoodsDetail: function(val) {
				this.$emit('goGoodsDetail',val);
			},
			// 商铺首页滚动 navbar 吸顶
			scrollHome: function(e) {
				this.$emit('scrollHome',e.detail.scrollTop >= this.storeHeight);
			}
		},
		mounted: function() {
			const query = uni.createSelectorQuery().in(this);
			query
				.select('#guarantee')
				.boundingClientRect(data => {
					this.storeHeight = data.top;
				})
				.exec();
		},
	};
</script>
<style lang="scss">
	.float {
		z-index: 999;
		position: fixed;
		right: 30rpx;
		bottom: 150rpx;
		image {
			width: 80rpx;
			height: 80rpx;
		}
	}
	.store-home {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		display: flex;
		flex-direction: column;
		background: left top/750rpx 360rpx no-repeat fixed;
		overflow: hidden;

		//品质保证
		.guarantee {
			display: flex;
			margin-bottom: 20rpx;

			.item {
				flex: 1;
				height: 148rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				background-color: #ffffff;

				image {
					width: 44rpx;
					height: 44rpx;
					display: inline-block;
					margin-bottom: 20rpx;
				}

				.text {
					font-size: 24rpx;
					color: #222222;
				}
			}
		}

		//品质保证
		.recommend {
			background-color: #ffffff;
			padding: 30rpx;
			margin-bottom: 20rpx;

			.top {
				display: flex;
				flex-direction: column;
				margin-bottom: 40rpx;
				.title {
					text-align: center;
					font-size: 34rpx;
					font-weight: 700;
					color: #222222;
					margin-bottom: 13rpx;
				}

				.subtitle {
					display: flex;
					justify-content: center;
					align-items: center;

					text {
						font-size: 24rpx;
						color: #222;
						padding: 0 17rpx;
					}

					span {
						width: 88rpx;
						border: 1rpx solid #bdbdbd;
					}
				}
			}

			.recommend-goods {
				display: flex;
				flex-wrap: nowrap;

				.item:nth-child(2) {
					margin: 0 17rpx;
				}

				.item {
					width: 219rpx;

					image {
						width: 219rpx;
						height: 219rpx;
						border-radius: 8rpx;
						margin-bottom: 16rpx;
					}

					.name {
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						font-size: 26rpx;
						color: #333;
						font-weight: bold;
						padding: 16rpx 0 4rpx 0;
					}

					.price {
						font-size: 24rpx;
						font-weight: bold;
						color: #db4234;
					}
				}
			}
		}

		.search {
			margin: 12rpx 120rpx 0 20rpx;
		}

		.store {
			background-color: #ffffff;
			position: relative;
			z-index: 6;
			display: flex;
			align-items: center;
			padding: 20rpx;
			margin-bottom: 20rpx;
			height: 136rpx;

			image {
				width: 74rpx;
				height: 74rpx;
				border-radius: 6rpx;
				margin-right: 20rpx;
			}

			.text {
				display: flex;
				flex-direction: column;
				flex: 1;
				min-width: 0;
				margin-right: 20rpx;

				.name {
					flex: 1;
					min-width: 0;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-weight: bold;
					font-size: 32rpx;
					line-height: 1;
					color: #000;
				}

				.score {
					display: flex;
					align-items: center;
					margin-top: 17rpx;
					font-weight: 400;
					font-size: 24rpx;
					line-height: 1;
					color: #ffffff;
				}
			}

			.goodssum {
				display: flex;
				flex-direction: column;
				justify-content: center;

				.sum {
					text-align: center;
					font-size: 32rox;
					font-weight: bold;
					color: #000000;
				}

				.ww {
					font-size: 20rpx;
					color: #999999;
				}
			}
		}

		.main {
			flex: 1;
			min-height: 0rpx;
		}

		.goods-wrap {
			.top {
				display: flex;
				flex-direction: column;
				padding-bottom: 40rpx;
				background-color: #F6F6F6;

				.title {
					text-align: center;
					font-size: 34rpx;
					font-weight: 700;
					color: #222222;
					padding-bottom: 13rpx;
				}

				.subtitle {
					display: flex;
					justify-content: center;
					align-items: center;

					text {
						font-size: 24rpx;
						color: #222;
						padding: 0 17rpx;
					}

					span {
						width: 88rpx;
						border: 1rpx solid #bdbdbd;
					}
				}
			}
		}

		.goods {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			padding-top: 20rpx;
			padding-right: 20rpx;
			padding-left: 20rpx;
			background-color: #f5f5f5;
			width: 750rpx;

			.item {
				width: 345rpx;
				border-radius: 16rpx;
				margin-bottom: 20rpx;
				background-color: #ffffff;
				overflow: hidden;

				.image {
					width: 345rpx;
					height: 345rpx;

					image {
						display: block;
						width: 100%;
						height: 100%;
					}
				}

				.text {
					padding: 20rpx 20rpx 25rpx;

					.name {
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
						font-weight: 500;
						font-size: 30rpx;
						color: #222222;
					}

					.money-wrap {
						margin-top: 20rpx;

						.money {
							font-weight: bold;
							font-size: 26rpx;
							color: #e93323;

							text {
								font-size: 34rpx;
								line-height: 1;
							}
						}

						.label {
							display: flex;
							flex-wrap: wrap;

							.ticket {
								height: 26rpx;
								padding-right: 9rpx;
								padding-left: 9rpx;
								border: 1rpx solid #e93323;
								border-radius: 4rpx;
								margin-left: 10rpx;
								font-weight: 500;
								font-size: 20rpx;
								line-height: 24rpx;
								color: #e93323;
								margin-top: 17rpx;
							}

							.pinkage {
								height: 26rpx;
								padding-right: 9rpx;
								padding-left: 9rpx;
								border: 1px solid #6b78ab;
								border-radius: 4rpx;
								margin-left: 10rpx;
								font-weight: 500;
								font-size: 20rpx;
								line-height: 24rpx;
								color: #6b78ab;
								margin-top: 17rpx;
							}
						}
					}

					.score {
						margin-top: 20rpx;
						font-weight: 500;
						font-size: 20rpx;
						line-height: 1;
						color: #737373;
					}
				}

				.foot {
					display: flex;
					justify-content: center;
					align-items: center;
					height: 52rpx;
					background: linear-gradient(to right, #f11b09, #f67a38);
					font-weight: 500;
					font-size: 24rpx;
					color: #ffffff;

					.iconfont {
						margin-right: 10rpx;
						font-size: 22rpx;
						line-height: 1;
					}
				}
			}
		}

		.column {
			padding: 0;
			background-color: #ffffff;

			.item {
				position: relative;
				display: flex;
				align-items: center;
				width: 100%;
				padding: 30rpx 20rpx;
				border-radius: 0;
				margin-bottom: 0;

				&::before {
					content: ' ';
					position: absolute;
					top: 0;
					right: 20rpx;
					left: 250rpx;
					border-top: 1rpx solid #f5f5f5;
				}

				.image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 16rpx;
					overflow: hidden;
				}

				.text {
					position: relative;
					flex: 1;
					min-width: 0;
					padding-top: 0;
					padding-right: 0;
					padding-bottom: 0;

					.name {
						color: #282828;
					}

					.money-wrap {
						display: flex;
						flex-direction: column;
						align-items: flex-start;
						margin-top: 52rpx;

						.ticket {
							height: 28rpx;
							padding-right: 12rpx;
							padding-left: 12rpx;
							border: none;
							border-radius: 0;
							margin-top: 17rpx;
							margin-left: 0;
							background: url(@/static/images/yh.png) top left/100% 100% no-repeat;
							line-height: 28rpx;
						}

						.pinkage {
							height: 26rpx;
							padding-right: 9rpx;
							padding-left: 9rpx;
							border: 1px solid #6b78ab;
							border-radius: 4rpx;
							margin-left: 10rpx;
							margin-top: 17rpx;
							font-weight: 500;
							font-size: 20rpx;
							line-height: 24rpx;
							color: #6b78ab;
						}
					}
				}

				.foot {
					position: absolute;
					right: 20rpx;
					bottom: 30rpx;
					height: 44rpx;
					padding-right: 17rpx;
					padding-left: 17rpx;
					border-radius: 22rpx;
					font-size: 22rpx;
					color: #f5f5f5;
				}
			}
		}
	}
</style>
